import { getAllChannels, getUserChannels } from '@/api/channels'

const state = {
  userChannel: [],
  allChannel: []
}
const mutations = {
  setUserChannel(state, value) {
    state.userChannel = value
  },
  addUserChannel(state, value) {
    state.userChannel.push(value)
  },
  setAllChannel(state, value) {
    state.allChannel = value
  }
}
const actions = {
  async getUserChannels(context) {
    const res = await getUserChannels()
    console.log('获取用户频道', res)
    context.commit('setUserChannel', res.data.channels)
  },
  async getAllChannels(context) {
    const res = await getAllChannels()
    console.log('获取所有频道', res)
    context.commit('setAllChannel', res.data.channels)
  }
}
const getters = {
  optionChannel(state) {
    return state.allChannel.filter(
      v => !state.userChannel.some(item => item.id === v.id)
    )
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
